package com.nf.handlers;

import com.nf.Constants;
import com.nf.MiniBasicRowProcessor;
import com.nf.MiniResultSetHandler;
import com.nf.MiniRowProcessor;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 　　* @description: TODO
 * 　　* @param
 * 　　* @return
 * 　　* @throws
 * 　　* @author Administrator
 * 　　* @date $ $
 *
 */

public class MiniArrayHandler implements MiniResultSetHandler<Object[]> {

    private final MiniRowProcessor convert;

    public MiniArrayHandler() {
        this(Constants.DEFAULT_ROW_PROCESSOR);
    }

    public MiniArrayHandler(MiniRowProcessor convert) {
        super();
        this.convert = convert;
    }

    @Override
    public Object[] handle(ResultSet rs) throws SQLException {
        return rs.next() ? this.convert.toArray(rs) : Constants.EMPTY_ARRAY;
    }
}
